import viz
import vizshape

sounds = list()

sounds.append("resources/sounds/red.wav")
sounds.append("resources/sounds/green.wav")
sounds.append("resources/sounds/blue.wav")
sounds.append("resources/sounds/yellow.wav")
sounds.append("resources/sounds/wrong.wav")

emitters = list()

emitters.append(vizshape.addCube(0,pos=[-150,19,150]).playsound(sounds[0]))
emitters.append(vizshape.addCube(0,pos=[200,19,250]).playsound(sounds[1]))
emitters.append(vizshape.addCube(0,pos=[-150,19,-100]).playsound(sounds[2]))
emitters.append(vizshape.addCube(0,pos=[200,19,-225]).playsound(sounds[3]))
emitters.append(vizshape.addCube(0,pos=[62, 0, 62]).playsound(sounds[4]))

for emitter in emitters:
	emitter.stop()
	emitter.minmax(10, 100)

class VizPlayAction(viz.ActionClass):
		
	def begin(self, object):
		self.which = self._actiondata_.data[0]
		emitters[self.which].play()
		
	def update(self, elapsed, object):
		self.end(object)
			
	def end(self, object):
		viz.ActionClass.end(self,object)
		
class VizStopAction(viz.ActionClass):
		
	def begin(self, object):
		self.which = self._actiondata_.data[0]
		self.timeElapsed = 0
		emitters[self.which].stop()
		
	def update(self, elapsed, object):
		self.end(object)
			
	def end(self, object):
		viz.ActionClass.end(self,object)
		
		
def play3DSound(which):
	action = viz.ActionData()
	action.data = [which]
	action.actionclass = VizPlayAction
	return action
	
def stop3DSound(which):
	action = viz.ActionData()
	action.data = [which]
	action.actionclass = VizStopAction
	return action